﻿using PMS.Data.Entities.SystemModules;
using PMS.Services.EntityServices;

namespace PMS.Services.EventHandler.Caching
{
    /// <summary>
    /// Represents a SystemModule cache event consumer
    /// </summary>
    public partial class SystemModuleCacheEventHandler : CacheEventHandler<SystemModule>
    {
        /// <summary>
        /// 分别针对Insert/Update/Delete进行操作，
        /// 如果操作逻辑相同，可以调用 ClearCache(Setting entity)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="entityEventType"></param>
        protected override void ClearCache(SystemModule entity, EntityEventType entityEventType)
        {
            ClearCache(entity);
            switch(entityEventType)
            {
                case EntityEventType.Update:
                case EntityEventType.Delete:
                    var key = _cacheKeyService.PrepareKey(CacheKeyConfigs.ModuleAssignedButtonsCachKey, entity.Id);
                    Remove(key);
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// Clear cache data
        /// </summary>
        /// <param name="entity">Entity</param>
        protected override void ClearCache(SystemModule entity)
        {
            RemoveByPrefix(CacheKeyConfigs.SystemModulesAllPrefixCacheKey);
        }
    }

}
